package com.zygvip.demand.service.impl;

import com.google.common.collect.Lists;
import com.zygvip.demand.dao.AppIndustryDao;
import com.zygvip.demand.entity.AppIndustry;
import com.zygvip.demand.service.AppIndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description
 *
 * @author 马乌提
 * @create 2018-02-05 15:39
 */
@Service
public class AppIndustryServiceImpl implements AppIndustryService{

    @Autowired
    private AppIndustryDao appIndustryDao;


    @Override
    public List<AppIndustry> findByParentId(Integer parentId) {
        Iterable<AppIndustry> industries = appIndustryDao.findAll();
        List<AppIndustry> list = Lists.newArrayList(industries);
        return list;
    }

    @Override
    public AppIndustry findById(Integer id) {
        return appIndustryDao.findOne(id);
    }

    @Override
    public List<AppIndustry> findAll() {
        Sort.Direction direction = Sort.Direction.ASC;
        String[] members = new String[]{"parentId","sort"};
        Sort sort = new Sort(direction,members);
        Iterable<AppIndustry> industries = appIndustryDao.findAll(sort);
        List<AppIndustry> list = Lists.newArrayList(industries);
        return list;
    }
}
